<?php

namespace app\staff\model;

use think\Model;

class CaringTaskOrder extends Model
{
    // 表名
    protected $name = 'caring_task_order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    // 追加属性
    protected $append = [
        // 'completiontime_text',
        // 'order_receiving_time_text',
        // 'status_text'
    ];
    

    
    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2')];
    }


    public function getCompletiontimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['completiontime']) ? $data['completiontime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getOrder_receiving_timeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['order_receiving_time']) ? $data['order_receiving_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setCompletiontimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setOrder_receiving_timeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }
}
